﻿#define TEST

using System;
using System.IO;
using System.Threading;
using Aliyun.OSS.Common;
using System.Text;
using Aliyun.OSS.Util;

namespace Aliyun.OSS.Sdk.JSST
{
    /// <summary>
    /// putting object.
    /// 本期仅PutObjectFromFile可用；
    /// 注意：其它方法（私有）仅能用于测试。
    /// 张睿 2017-10-30
    /// </summary>
    public class PutObjectHelp
    {
        private static PutObject putObject = null;

        /// <summary>
        /// 静态构造
        /// 张睿 2017-11-09
        /// </summary>
        static PutObjectHelp()
        {
            putObject = new PutObject();
        }

        /// <summary>
        /// 环境变量改变
        /// 张睿 2017-11-09
        /// </summary>
        public static void Ini()
        {
            putObject.Ini();
        }

        /// <summary>
        /// put localFilePath to oss
        /// 张睿 2017-10-30
        /// </summary>
        /// <param name="key">（远程）对象名（即 文件名）</param>
        /// <param name="localFilePath">本地文件完整路径</param>
        /// <param name="resultMessage">返回信息</param>
        public static int PutObjectFromFile(string key, string localFilePath, out Result resultMessage)
        {
            PutObjectFile putObjectFile = new PutObjectFile(putObject, Config.BucketName, key, localFilePath);
            return putObjectFile.PutObjectFromFile(out resultMessage);
        }

        /// <summary>
        /// put localFilePath to oss
        /// 张睿 2017-10-30
        /// </summary>
        /// <param name="bucketName">存储空间 名</param>
        /// <param name="key">（远程）对象名（即 文件名）</param>
        /// <param name="localFilePath">本地文件完整路径</param>
        /// <param name="resultMessage">返回信息</param>
        /// <returns>0:成功 1：失败 100：配置信息错误 101：其他异常</returns>
        public static int PutObjectFromFile(string bucketName, string key, string localFilePath, out Result resultMessage)
        {
            PutObjectFile putObjectFile = new PutObjectFile(putObject, bucketName, key, localFilePath);
            return putObjectFile.PutObjectFromFile(out resultMessage);
        }

        /// <summary>
        /// 获取OSS临时访问图片
        /// </summary>
        /// <param name="bucketName"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static Uri GeneratePresignedUri(string bucketName, string key)
        {
            return putObject.GeneratePresignedUri(bucketName, key);

        }
    }
}
